package com.key.puzzlemodel.dialog

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.widget.TextView
import com.key.puzzlemodel.R
import com.key.puzzlemodel.util.BitmapUtil

/**
 *
 * @功能描述:
 * @创建时间:     2022/1/20
 * @创建者:       阳
 * @修改时间:     2022/1/20
 * @修改者:       阳
 */
@SuppressLint("StaticFieldLeak")
object DialogUtil {

    var dialog: Dialog? = null
    var txEmpty: TextView? = null

    fun showLoading(context: Context, content: String = "", cancelable: Boolean = false) {
        dialog = MyDialog(context, R.style.loading_dialog)
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_loading_layout_puzzle, null)
        txEmpty = view.findViewById<TextView>(R.id.tx_empty)

        if (content.isNotEmpty()){
            txEmpty!!.text = content
        }

        dialog!!.setContentView(view)

        if (!cancelable) {
            dialog!!.setCancelable(cancelable)
        } else {
            dialog!!.setCanceledOnTouchOutside(false)
        }

        val attributes = dialog!!.window?.attributes
        attributes!!.width = BitmapUtil.dip2px(context, 150f)
        attributes.height = BitmapUtil.dip2px(context, 150f)
        dialog!!.window?.attributes = attributes
        dialog!!.show()
    }


    fun closeDialog() {
        if (null != dialog) {
            dialog!!.dismiss()
        }
    }

    interface OnRenameItemClick {
        fun onConfirm(pathName: String)
    }
}